﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using Modules.Constructor;

namespace ManagementApi.Models.Account
{
    /// <summary>
    /// 建设单位信息 编辑模型
    ///</summary>
    [Serializable]
    public class ConstructorCreateForm
    {
        /// <summary>
        /// 建设单位ID
        ///</summary>
        public int? ConstructorId { get; set; }

        /// <summary>
        /// 建设单位类型:个人、事业单位、政府机关、企业
        ///</summary>
        [Display(Name = "建设单位类型:个人、事业单位、政府机关、企业")]
        [Required(ErrorMessage = "{0}不能为空")]
        public ConstructorType? Type { get; set; }

        /// <summary>
        /// 建设单位类型名称
        /// </summary>
        public string? TypeName { get; set; }

        /// <summary>
        /// 建设单位名称、个人姓名
        ///</summary>
        [Display(Name = "建设单位名称、个人姓名")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string Name { get; set; }

        /// <summary>
        /// 建设信用代码、身份证号码
        ///</summary>
        [Display(Name = "建设信用代码、身份证号码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string Code { get; set; }

        /// <summary>
        /// 归属省代码
        ///</summary>
        [Display(Name = "归属省代码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int ProvinceCode { get; set; }

        /// <summary>
        /// 归属地市代码
        ///</summary>
        [Display(Name = "归属地市代码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int CityCode { get; set; }

        /// <summary>
        /// 归属区县代码
        ///</summary>
        [Display(Name = "归属区县代码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public int AreaCode { get; set; }

        /// <summary>
        /// 所属区域
        /// </summary>
        public string? AreaName { get; set; }

        /// <summary>
        /// 注册地址
        ///</summary>
        [Display(Name = "注册地址")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string RegAddr { get; set; }

        /// <summary>
        /// 办公地址
        ///</summary>
        [Display(Name = "办公地址")]
        public string OfficeAddr { get; set; }

        /// <summary>
        /// 法人姓名
        ///</summary>
        [Display(Name = "法人姓名")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string Legalman { get; set; }

        /// <summary>
        /// 法人身份证号码
        ///</summary>
        [Display(Name = "法人身份证号码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string LegalCardno { get; set; }

        /// <summary>
        /// 法人手机号码
        ///</summary>
        [Display(Name = "法人手机号码")]
        [Required(ErrorMessage = "{0}不能为空")]
        public string LegalMobile { get; set; }

        /// <summary>
        /// 联系人
        ///</summary>
        [Display(Name = "联系人")]
        //[Required(ErrorMessage = "{0}不能为空")]
        public string? LinkMan { get; set; }

        /// <summary>
        /// 联系人电话
        ///</summary>
        [Display(Name = "联系人电话")]
        public string? LinkTel { get; set; }

        /// <summary>
        /// 验证码
        /// </summary>
        [Display(Name = "验证码")]
        public string? VerificationCode { get; set; }

        /// <summary>
        /// 登陆密码
        ///</summary>
        [Display(Name = "登陆密码")]
        [MinLength(8,ErrorMessage = "密码至少8位,必须由大小写字母+数字组合")]
        public string? Password { get; set; }

        public virtual ConstructorInfo AsConstructor()
        {
            ConstructorInfo constructor = new();
            constructor.Type = Type.Value;
            constructor.Name = Name;
            constructor.Code = Code;
            constructor.ProvinceCode = ProvinceCode;
            constructor.CityCode = CityCode;
            constructor.AreaCode = AreaCode;
            constructor.RegAddr = RegAddr;
            constructor.OfficeAddr = OfficeAddr;
            constructor.Legalman = Legalman;
            constructor.LegalCardno = LegalCardno;
            constructor.LegalMobile = LegalMobile;
            constructor.LinkTel = LinkTel;
            constructor.LinkMan = LinkMan;
            return constructor;
        }
    }

    public static partial class ConstructorExceptions
    {
        /// <summary>
        /// 下拉列表
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static LabelValue<int> AsPullDownDto(this ConstructorInfo entity)
        {
            LabelValue<int> data = new LabelValue<int>();
            data.Value = entity.ConstructorId;
            data.Label = entity.Name;
            data.Extend1 = entity.Code;
            return data;
        }
    }
}